#include "controltypeform.h"
#include "datamanager/datamanagedialog.h"
#include "models/command.h"
#include "models/operatelogmodel.h"
#include "ui_controltypeform.h"
#include"MessageBox.h"

ControlTypeForm::ControlTypeForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::ControlTypeForm)
{
    setAttribute(Qt::WA_StyledBackground, true);
    ui->setupUi(this);
    scaleWidgets(this,g_xScale,g_yScale);

}
void ControlTypeForm::scaleWidgets(QWidget *widget, double xScale, double yScale)
{
    setFixedSize(int(widget->width() * xScale),int(widget->height() * yScale));
    for (QWidget * child : widget->findChildren<QWidget*>()) {
        QRect geom = child->geometry();
        int width = qMax(1, static_cast<int>(geom.width() * xScale));
        //当按钮高度比较大时使用y方向比例，当按钮比较小时使用x比例，防止按钮被压扁
        int height = qMax(1, static_cast<int>((geom.height() == geom.width() ? int(geom.height() * xScale) : int(geom.height() * yScale))));
         child->setFixedSize(width,height);
        child->move(int(geom.left() * xScale),int(geom.top() * yScale));
        QFont font = child->font();
        if(font.pixelSize()> 0)
            font.setPixelSize(int(font.pixelSize()*xScale));
        else if(font.pointSize()> 0)
            font.setPixelSize(int(font.pointSize()*xScale));
        child->setFont(font);
    }
}

ControlTypeForm::~ControlTypeForm()
{
    delete ui;
}

void ControlTypeForm::on_Exit_pushButton_clicked()
{
    if(question(this,tr("确定要退出程序吗？")) == 0)
        qApp->exit(0);
}

void ControlTypeForm::on_data_btn_clicked()
{
    DataManageDialog dlg(this);
    dlg.exec();
}


void ControlTypeForm::on_ctrl_site_btn_clicked()
{
    OPERATE_LOG("选择功能：训练场");
    emit enterCtrlSite();
}

void ControlTypeForm::on_ctrl_sigle_btn_clicked()
{
    OPERATE_LOG("选择功能：单机控制");
    emit enterCtrlRobot();
}




